package com.zzy.broker.server;

import com.zzy.broker.handler.ConnectHandler;
import com.zzy.broker.handler.PublishHandler;
import com.zzy.broker.handler.SubscribeHandler;
import com.zzy.broker.server.codec.MqttDecoder;
import com.zzy.broker.server.codec.MqttEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;


public class NettyServerInitializer  extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG));
        ch.pipeline().addLast(new MqttDecoder());      // decode bytes -> MqttRawMessage
        ch.pipeline().addLast(new MqttEncoder());      // encode ByteBuf -> bytes
        ch.pipeline().addLast(new ConnectHandler());   // 处理 CONNECT 消息
        ch.pipeline().addLast(new SubscribeHandler()); // 处理 SUBSCRIBE 消息
        ch.pipeline().addLast(new PublishHandler());   // 处理 PUBLISH 消息（发送/接收）
        // 后续可加入 UnsubscribeHandler、PingHandler、DisconnectHandler 等
    }
}
